# Author: mosra <mosra@centrum.cz>
pkgname=corrade
pkgver=dev
pkgrel=1
pkgdesc="C++11/C++14 multiplatform utility library"
arch=('i686' 'x86_64')
url="https://magnum.graphics/corrade/"
license=('MIT')
makedepends=('cmake' 'ninja')
options=('!strip' '!buildflags')
provides=('corrade-git')

_rootdir=$startdir/../../

_buildtype=Release
# _buildtype=RelWithDebInfo

build() {
    mkdir -p "$_rootdir/build"
    cd "$_rootdir/build"

    # RelWithDebInfo is enabled but not built -- it's meant for profiling from
    # within the build dir
    cmake .. \
        -DCMAKE_CONFIGURATION_TYPES="Debug;Release;RelWithDebInfo" \
        -DCMAKE_CROSS_CONFIGS=all \
        -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O2 -g -DNDEBUG -fno-omit-frame-pointer" \
        -DCMAKE_INSTALL_PREFIX=/usr \
        -DCORRADE_BUILD_TESTS=ON \
        -G "Ninja Multi-Config"
    ninja all:Debug all:$_buildtype
}

check() {
    cd "$_rootdir/build"
    export CORRADE_TEST_COLOR=ON

    for config in Debug $_buildtype; do
        # The Tester test *needs* benchmarks enabled to pass properly
        ctest -C $config --output-on-failure -R TestSuiteTesterTest
        CORRADE_TEST_SKIP_BENCHMARKS=ON ctest -C $config --output-on-failure -j9 -E TestSuiteTesterTest
    done
}

package() {
    cd "$_rootdir/build"
    DESTDIR="$pkgdir/" ninja install:Debug

    # Prevent the Release build from overwriting Debug binaries
    for i in $(ls $pkgdir/usr/bin/corrade-*); do
        mv ${i}{,d}
    done

    if [ "$_buildtype" = RelWithDebInfo ]; then
        DESTDIR="$pkgdir/" ninja install:$_buildtype
    else
        DESTDIR="$pkgdir/" ninja install/strip:$_buildtype
    fi
}
